<template>
	<view class="container">
		<template v-for="(item, index) in list">
			<view class="container-box">
				<view class="container-box-left">
					<image :src="item.content.avatar" mode="aspectFill"></image>
				</view>
				<view class="container-box-right">
					<view class="container-box-right-top">
						<h1>{{item.content.name}}</h1>
						<text v-if="item.associatedType===0">评论了你的动态</text>
						<text v-if="item.associatedType===1">回复了你的评论</text>
					</view>
					<view class="container-box-right-body" >
						<text>{{item.content.comment}}</text>
					</view>
					<view class="container-box-right-middle" @click="navTo(item)">
						<text>{{item.content.target}}</text>
					</view>
					<view class="container-box-right-bottom">
						<text>来自奇宠日记</text>
						<text>{{$util.dateUtils.format(item.createTime)}}</text>
					</view>
				</view>
			</view>
		</template>

		<!-- 没有商品 -->
		<view class="nodetails" style="height: 510px" v-if="list.length == 0">
		  <view class="nodetails_img">
		    <image src="http://qichong-1256206693-1256206693.cos.ap-nanjing.myqcloud.com/upload/20210617/3a7b53543eb8e61ccf6b16369db10a00.png" mode="widthFix" class="maxImage"></image>
		  </view>
		  <text>去发动态...</text>
		</view>
	</view>
</template>

<script>
	import {
		comment
	} from '@/api/message.js'
	export default {
		data() {
			return {
				list: []
			};
		},
		onLoad() {
			this.comment();
		},
		methods: {
			navTo(data) {
				let url = '';
				if (data.associatedType === 1) {
					url = '/subpkg/details/commentReply?id=' + data.associatedId;
				} else {
					let name = '动态';
					url = '/subpkg/details/details?id=' + data.associatedId + '&name=' + name;
				}
				uni.navigateTo({
					url: url
				})
			},
			comment() {
				let that = this;
				comment().then(res => {
					that.list = res.data;
					that.list.forEach(item => {
						if (item.content) {
							item.content = JSON.parse(item.content);
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		.container-box {
			box-sizing: border-box;
			padding: 36rpx 30rpx;
			display: flex;

			.container-box-left {
				margin-right: 20rpx;

				image {
					width: 72rpx;
					height: 72rpx;
					border-radius: 50%;
				}
			}

			.container-box-right {
				box-sizing: border-box;
				width: 87%;
				display: flex;
				flex-direction: column;
				align-items: flex-start;

				.container-box-right-top {
					padding-top: 10rpx;
					display: flex;
					align-items: center;

					h1 {
						color: rgba(61, 61, 61, 1);
						font-size: 30rpx;
						margin-right: 20rpx;
						font-weight: bold;
					}

					text {
						color: rgba(61, 61, 61, 0.6);
						font-size: 24rpx;
					}
				}

				.container-box-right-body {
					color: rgba(61, 61, 61, 1);
					font-size: 28rpx;
					line-height: 55rpx;
					margin-top: 30rpx;
				}

				.container-box-right-middle {
					width: 100%;
					height: 78rpx;
					background-color: rgba(61, 61, 61, 0.05);
					border-radius: 10rpx;
					margin-top: 30rpx;
					padding: 0 24rpx;
					box-sizing: border-box;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					line-height: 78rpx;
					color: rgba(61, 61, 61, 0.6);
				}

				.container-box-right-bottom {
					width: 100%;
					color: rgba(61, 61, 61, 0.5);
					font-size: 24rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 30rpx 0 50rpx;
					border-bottom: 1rpx solid #f1f1f1;
				}
			}
		}
	}
	.nodetails {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding-bottom: 128rpx;
	
		.nodetails_img {
			.maxImage {
				width: 184rpx;
				height: 322rpx;
			}
		}
	
		text {
			font-size: 30rpx;
			margin-top: 20rpx;
			color: rgba(61, 61, 61, 0.3);
		}
	}
</style>
